﻿Imports ISNet.WebUI.WebGrid
Imports System
Imports System.Data
Imports System.Configuration
Imports System.Collections
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
Imports log4net

Partial Class mtFctParent
    Inherits System.Web.UI.Page

    Private Shared logger As ILog = LogManager.GetLogger("mtFctParent")

    Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
        ScreenName.Text = "ระบบจัดทำงบประมาณ  >>  ตั้งค่าระบบ >>  FctParent"
        'Session("users") = "bb0011"
        If Session("users") Is Nothing Then
            Response.Redirect("LoginForm.aspx")
        End If
        
        If IsPostBack = False Then
            PlanYearsTxt.Text = Session("PlanYear")
            Session("PlanYearTxt") = PlanYearsTxt.Text
            Session("SearchTxt") += " and PlanYear = " & PlanYearsTxt.Text
            'Else
            '    PlanYearsTxt.Text = Session("PlanYearTxt")

        End If

    End Sub

    Protected Sub WebGrid1_InitializeDataSource(ByVal sender As Object, ByVal e As ISNet.WebUI.WebGrid.DataSourceEventArgs) Handles WebGrid1.InitializeDataSource

        Dim adapter As New MasterDataSetTableAdapters.FctParentTableAdapter
        Dim dtTable As New MasterDataSet.FctParentDataTable

        Dim sql As String = "select * from FctParent "
        sql += " WHERE 1 = 1 "

        sql += Session("SearchTxt")

        sql += " ORDER BY PlanYear, FundCenterCode"

        adapter.SearchFctParent(dtTable, sql)
        'Response.Write(sql)

        Session("count_data") = dtTable.Rows.Count

        dtTable.Columns("PlanYear").AllowDBNull = True
        dtTable.Columns("FundCenterCode").AllowDBNull = True
        dtTable.Columns("parent1").AllowDBNull = True
        dtTable.Columns("parent2").AllowDBNull = True
        dtTable.Columns("parent3").AllowDBNull = True
        dtTable.Columns("parent4").AllowDBNull = True
        dtTable.Columns("parent5").AllowDBNull = True
        dtTable.Columns("parent1_name").AllowDBNull = True
        dtTable.Columns("parent2_name").AllowDBNull = True
        dtTable.Columns("parent3_name").AllowDBNull = True
        dtTable.Columns("parent4_name").AllowDBNull = True
        dtTable.Columns("parent5_name").AllowDBNull = True

        e.DataSource = dtTable

    End Sub

    Protected Sub WebGrid1_InitializeRow(ByVal sender As Object, ByVal e As ISNet.WebUI.WebGrid.RowEventArgs)
        ' don't edit column
        e.Row.Cells(0).ForceNoEdit = True
        e.Row.Cells(1).ForceNoEdit = True
        e.Row.Cells(2).ForceNoEdit = True
        e.Row.Cells(3).ForceNoEdit = True
        e.Row.Cells(4).ForceNoEdit = True
        e.Row.Cells(5).ForceNoEdit = True
        e.Row.Cells(6).ForceNoEdit = True
        e.Row.Cells(7).ForceNoEdit = True
        e.Row.Cells(8).ForceNoEdit = True
        e.Row.Cells(9).ForceNoEdit = True
        e.Row.Cells(10).ForceNoEdit = True
        e.Row.Cells(11).ForceNoEdit = True
    End Sub

    Protected Sub WebGrid1_InitializePostBack(ByVal sender As Object, ByVal e As ISNet.WebUI.WebGrid.PostbackEventArgs) Handles WebGrid1.InitializePostBack
        If e.Action = PostBackAction.Custom Then

        End If
    End Sub
    Protected Sub SearhBtn_Click(sender As Object, e As ImageClickEventArgs) Handles SearhBtn.Click
        Session("PlanYearTxt") = PlanYearsTxt.Text
        Session("FctCode") = fctrWebCombo.Value

        If fctrWebCombo.Value <> "" And fctrWebCombo.Text <> "" And Val(fctrWebCombo.Value) <> 0 Then
            Session("SearchTxt") = " and PlanYear = " & PlanYearsTxt.Text
            Session("SearchTxt") += " and FundCenterCode = '" & fctrWebCombo.Value & "'"
            WebGrid1.LayoutSettings.AllowAddNew = AddNew.No
        Else
            WebGrid1.LayoutSettings.AllowAddNew = AddNew.No
            Session("SearchTxt") = " and PlanYear = " & PlanYearsTxt.Text
        End If

        WebGrid1.ClearCachedDataSource()
        WebGrid1.RebindDataSource()
        t_countdata.Visible = True
        If Val(Session("count_data")) > 0 Then
            L_CountData.Text = FormatNumber(Val(Session("count_data")), 0) & " รายการ"
        Else
            L_CountData.Text = "ไม่พบข้อมูลที่ค้นหา"
        End If
    End Sub
End Class
